const App = getApp();
import {
	url
} from '../../modelApi/url_config.js'
Page({
	data: {
		statusBarHeight: "",
		statusBarPadding: "",
		cardArray: ['农行', '建行', '广发', '招商'],
		arrayIndex: '',
		money: '', // 所提现金额
		cardName: '', // 卡名
		cardNumber: '', // 卡号
		cardNumberList: '',
		passNum: '',
		isShowTixian:false,
		toasttip:'',
		showtoasttip:false,
	},
	onLoad: function (options) {
		this.setData({
			statusBarPadding: App.globalData.navTop,
			statusBarHeight: App.globalData.navHeight,
		});
	},
	showToastFunc(title) {
		this.setData({
			toasttip:title,
			showtoasttip:true,
		})
		setTimeout(()=>{
			this.setData({
				showtoasttip:false,
			})
		}, 2000)
	},
	isShowTixianFunc() {
		if (this.data.cardName === '') {
			this.showToastFunc("请输入开户姓名！")
			return;
		}
		if (this.data.arrayIndex === '') {
			this.showToastFunc("请选择开户行！")
			return;
		}
		if (this.data.cardNumber === '') {
			this.showToastFunc("请输入银行卡号码！")
			return;
		}
		if (this.data.money === '') {
			this.showToastFunc("请输入提现金额！")
			return;
		}
		this.setData({
			isShowTixian:true
		})
	},
	closeDialog() {
		this.setData({
			isShowTixian:false
		})
	},
	// 银行选择
	bindPickerChange: function (e) {
		this.setData({
			arrayIndex: e.detail.value
		})
	},
	/* 获取提现金额 */
	formMoney(e) {
		const text = e.detail.value;
		this.setData({
			money: text
		})
	},
	formName(e) {
		let arr = this.del_blank(e.detail.value).split("");
		this.setData({
			cardNumberList: arr
		})
			for (var i = 0; i < this.data.cardNumberList.length; i++) {
				if (i > 0 && i % 4 == 0 && i < 8) {
					this.add_blank(i);
				} else if (i >= 8 && i % 5 == 4) {
					this.add_blank(i);
				}
			}
			const value = this.data.cardNumberList.join("");
		this.setData({
			cardNumber: value
		})
	},
	// 添加空格
	add_blank(i) {
		if (this.data.cardNumberList[i] && this.data.cardNumberList[i] != " ") {
			this.data.cardNumberList.splice(i, 0, " ");
		}
	},
	// 删除空格
	del_blank(str) {
		return str.replace(/\s+/g, "");
	},
	formNumber(e) {
		const text = e.detail.value;
		this.setData({
			cardName: text
		})
	},

})